// 1. 命令接口
class Command {
    execute() {}
  }
  
  // 2. 具体命令类
  class OrderFoodCommand extends Command {
    constructor(receiver, foodItem) {
      super();
      this.receiver = receiver;
      this.foodItem = foodItem;
    }
  
    execute() {
      this.receiver.prepareFood(this.foodItem);
    }
  }
  
  // 3. 接收者（餐厅厨师）
  class Chef {
    prepareFood(foodItem) {
      console.log(`厨师正在准备: ${foodItem}`);
    }
  }
  
  // 4. 请求者（服务员）
  class Waiter {
    constructor() {
      this.orders = [];
    }
  
    addOrder(command) {
      this.orders.push(command);
    }
  
    executeOrders() {
      this.orders.forEach(order => order.execute());
      this.orders = []; // 清空已执行的订单
    }
  }
  
  // 5. 客户点餐
  const chef = new Chef();  // 餐厅厨师
  const waiter = new Waiter();  // 服务员
  
  // 客户点餐
  const order1 = new OrderFoodCommand(chef, '炸鸡');
  const order2 = new OrderFoodCommand(chef, '汉堡');
  const order3 = new OrderFoodCommand(chef, '沙拉');
  
  // 服务员将订单传递给命令
  waiter.addOrder(order1);
  waiter.addOrder(order2);
  waiter.addOrder(order3);
  
  // 服务员执行命令
  waiter.executeOrders();
  